#include "StdAfx.h"
#include "ZlibWrapper.h"

#pragma comment(lib, "zlib1.lib")


CZlibWrapper::CZlibWrapper(void)
{
}


CZlibWrapper::~CZlibWrapper(void)
{
}

int CZlibWrapper::zlibCompress(Byte *dest, uLong* destLen, const Byte *source, uLong sourceLen)
{
	return compress(dest, destLen, source, sourceLen);
}

int CZlibWrapper::zlibUncompress(Byte *dest, uLong *destLen, const Byte *source, uLong sourceLen)
{
	return uncompress(dest, destLen, source, sourceLen);
}

int CZlibWrapper::zlibCompress(const Byte *source, uLong sourceLen, string& strDest)
{
	if (sourceLen <= 0 || source == nullptr)
	{
		return -1;
	}
	uLong destLen = 30 * 1024 * 1024;
	Byte *dest = new Byte[destLen];
	memset(dest, 0, destLen);
	int res = compress(dest, &destLen, source, sourceLen);
	if (res == 0)
	{
		strDest.append((char*)dest, destLen);
	}
	delete [] dest;

	return 0;
}




